﻿#ifndef __SS_OBJECT_H__
#define __SS_OBJECT_H__
#include "ss3dDefine.h"
#include "string/ssString.h"
#include "algorithms/md5.h"
#include "algorithms/ssHash.h"

namespace StarSeeker
{

class ssObject
{
public:
	ssObject():m_hashNum(0), m_ref(0), m_enable(false)
	{
	}
	ssObject(const char* name) :m_hashNum(0), m_ref(0), m_enable(true)
	{
		SetName(name);
	}
	virtual ~ssObject()
	{
	}

	void SetName(const char* name)
	{
		if (name)
		{
			m_name = name;
			GetMd5(m_name.GetString(), m_name.Length(), m_hash);
			m_hashNum = DJBHashCode(m_name.GetString(), m_name.Length());
		}
		else
		{
			m_name.Empty();
		}
	}
	const ssString& Name()
	{
		return m_name;
	}
	const char* Hash()
	{
		return m_hash;
	}
	ulint HashNum() const
	{
		return m_hashNum;
	}
	bool NameIs(const char* name)
	{
		return m_name == name;
	}
	void IncRef()
	{
		++m_ref;
	}
	void DecRef()
	{
		--m_ref;
	}
	i32 Ref()
	{
		return m_ref;
	}

private:
	ssString	m_name;
	char		m_hash[34];
	ulint		m_hashNum;
	i32			m_ref;
public:
	bool		m_enable;
};

}
#endif
